package com.example.activity

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.widget.RelativeLayout
import androidx.core.app.NavUtils
import com.example.activity.fragment.game.view.HatView

class GameActivity : AppCompatActivity() {
    @SuppressLint("ClickableViewAccessibility")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_game)


        //设置返回的层级指示（返回）
        NavUtils.getParentActivityName(this)?.let {
            supportActionBar?.setDisplayHomeAsUpEnabled(true)
        }


        //添加帽子视图进游戏布局中
        val hatView = HatView(this)
        hatView.setOnTouchListener{ _: View, motionEvent: MotionEvent ->
            hatView.bitmapX = motionEvent.x - 200
            hatView.bitmapY = motionEvent.y - 200
            hatView.invalidate()
            return@setOnTouchListener true
        }

        //注意，一个activity中获取另一个activity的组件(view)需要用到LayoutInflater
        val gameView = findViewById<RelativeLayout>(R.id.game_view)
        //天剑进游戏的布局管理器中
        gameView.addView(hatView)
    }
}